package com.hzqy.service.industry.medical;

import com.alibaba.fastjson.JSONObject;
import com.hzqy.persistence.dao.industry.AlertInfoDao;
import com.hzqy.web.vo.AlertInfoVo;
import com.hzqy.web.vo.InformationSynVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.*;

@Service
public class AlertInfoService {
    
    protected final Logger LOG = LoggerFactory.getLogger(getClass());
    
    @Resource
    private AlertInfoDao alertInfoDao;
    
    public int addAlertInfo(JSONObject request) {
        LOG.debug(request.toJSONString());
        AlertInfoVo alertInfoVo=new AlertInfoVo();
        alertInfoVo.setF_al_equ_id(request.get("telDeviceId")==null?"":request.get("telDeviceId").toString());
        alertInfoVo.setF_al_data(request.get("data")==null?"":request.get("data").toString());
        alertInfoVo.setF_al_pushTime(request.get("time")==null?"":request.get("time").toString());
        alertInfoVo.setF_al_equ_type(request.get("notifyType")==null?"":request.get("notifyType").toString());
        alertInfoVo.setF_al_type(request.get("type")==null?-1:Integer.parseInt(request.get("type").toString()));
        int i = alertInfoDao.insertAlertInfo(alertInfoVo);
        return i;
    }
    
    public List<AlertInfoVo> selectAlertInfo(AlertInfoVo alertInfoVo) {

        List<AlertInfoVo> alertInfoVoList=new ArrayList<>();
        List<AlertInfoVo> alertInfoVoList1 = alertInfoDao.selectAlertInfo(alertInfoVo);
        alertInfoVoList.add(alertInfoVoList1.get(0));
        return alertInfoVoList;
    }
    
    public List<AlertInfoVo> selectAlertInfoByPage(AlertInfoVo alertInfoVo, int pageSize, int pageNum) {
        Map<String,Object> map=new HashMap<>();
        List<AlertInfoVo> alertInfoVoList =null;
    
        List<AlertInfoVo> alertInfoVoList1 = alertInfoDao.selectAlertInfo(alertInfoVo);
        int total=alertInfoVoList1.size();
        int pageTotal=0;
        if (total%pageSize==0){pageTotal=total/pageSize;}
        else {pageTotal=total/pageSize+1;}
        if (pageNum>pageTotal){pageNum=pageTotal;}
        
        map.put("pageNum",(pageNum-1)*pageSize);
        map.put("pageSize",pageSize);
        map.put("f_al_id",alertInfoVo.getF_al_id());
        map.put("f_al_equ_id",alertInfoVo.getF_al_equ_id());
        map.put("f_al_equ_type",alertInfoVo.getF_al_equ_type());
        map.put("f_al_type",alertInfoVo.getF_al_type());
        map.put("f_al_data",alertInfoVo.getF_al_data());
        map.put("f_al_pushTime",alertInfoVo.getF_al_pushTime());
        map.put("f_al_createTime",alertInfoVo.getF_al_createTime());
        alertInfoVoList = alertInfoDao.selectAlertInfoByPage(map);
        return alertInfoVoList;
    }
}
